package com.yanqu.road.server.cmd.activity.yingxin;

import com.yanqu.road.pb.activity.YingXinProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.yingxin.YingXinModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_YINGXIN_RESTART, desc = "迎新夜宴重新开始游戏")
public class YingXinRestartGameCmd extends AbstractCommand {

    private int multi;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        YingXinProto.YingXinRestartReqMsg reqMsg = YingXinProto.YingXinRestartReqMsg.parseFrom(packet.getBytes());
        multi = reqMsg.getMultiType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        player.getModule(YingXinModule.class).checkUserData();
        ret = player.getModule(YingXinModule.class).restartGame(multi);
    }

    @Override
    public void sendData(GamePlayer player) {
        YingXinProto.YingXinRestartRespMsg.Builder builder = YingXinProto.YingXinRestartRespMsg.newBuilder();
        builder.setRet(ret);
        player.sendPacket(ClientProtocol.U_ACTIVITY_YINGXIN_RESTART, builder);
    }
}
